package com.project.slsx.adapter;

import android.util.Log;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.project.slsx.R;
import com.project.slsx.bean.StorageListBean;
import com.project.slsx.utils.GlideUtils;

import org.angmarch.views.NiceSpinner;

import java.util.ArrayList;
import java.util.List;

public class StorageList1Adapter extends BaseQuickAdapter<StorageListBean.ResultBean, BaseViewHolder> {
    public StorageList1Adapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder holder, StorageListBean.ResultBean item) {
        RequestOptions option = GlideUtils.getOption();
        ArrayList<String> supplierName = new ArrayList<>();
        List<StorageListBean.ResultBean.SupplierBean> supplier = item.getSupplier();
        if (supplier != null && supplier.size() > 0) {
            for (int i = 0; i < supplier.size(); i++) {
                supplierName.add(supplier.get(i).getName());
            }
        }
        Log.i(TAG, "convert: " + supplierName);
        ImageView thumb = holder.getView(R.id.iv_storage);
        CheckBox gift = holder.getView(R.id.cb_gift);
        NiceSpinner snipper = holder.getView(R.id.nice_spinner);
        snipper.attachDataSource(supplierName);
        Glide.with(mContext).load(item.getThumb()).apply(option).into(thumb);
        holder.setText(R.id.tv_storage_item_name, item.getTitle());
        holder.setText(R.id.ed_storage_number, item.getNumber());
        holder.setText(R.id.ed_storage_amount, item.getAmount());
        gift.setChecked(!item.getGift().equals("0"));
        holder.setText(R.id.tv_storage_profits, String.valueOf(item.getProfits()));
    }
}
